<?php

namespace App\Services;

use App\Models\BaseModel;
use App\Models\Bus;

class BusService extends BaseService
{
    /**
     * 公交列表
     * @return array
     */
    public function list()
    {
        // 设置对象
        $model = Bus::query();
        // 状态
        $model = $model->where('status', BaseModel::STATUS_ENABLE);
        // 获取列表
        $list = $model
            ->orderBy('sort', 'desc')
            ->orderBy('id', 'desc')
            ->get(['id', 'bus_name', 'bus_desc', 'bus_time', 'bus_line'])
            ->toArray();

        foreach ($list as &$item) {
            $item['bus_line'] = json_decode($item['bus_line'], true);
        }

        return $list;
    }
}
